/**
 * 页面初始化
 */
var adjustSkuTable=null;
var adjustSkuCompleteTable=null;
$(function () {
    showAdjustSkuTab();
});

function showAdjustSkuTab(){
    var orderId=$('#myid', window.parent.document).val();
    var tab = $('#tab', window.parent.document).val();
    if (tab == "complete"){
        $('#adjustSkuTable').hide();
        $('#adjustSkuCompleteTable').show();
        if (adjustSkuCompleteTable==null){
            adjustSkuCompleteTable = $('#adjustSkuCompleteTable').DataTable({
                "autoWidth": false,
                "processing": true,
                "serverSide": true,
                // "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "dom": '<"bottom"rtflp>',
                "searching": false,
                // "pagingType": "full_numbers",
                "paging": false,
                "deferRender": true,
                "ordering": false,
                "ajax": {
                    "url": "/extAdjust/getAdjustSku.action?adjustId="+$('#myid', window.parent.document).val()
                },
                "columns": [
                    {"data": "goodsCode","orderable": false},
                    {"data": "goodsName","orderable": false},
                    {"data": "skuCode","orderable": false},
                    {"data": "skuName","orderable": false},
                    {"data": "stockTypeName","orderable": false},
                    {"data": "batchCode","orderable": false},
                    {"data": "productDate","orderable": false},
                    {"data": "qty","orderable": false},
                    {"data": "stockQty","orderable": false},
                    {"data": "goodsSkuCost","orderable": false,"render": numberParser},
                    {"data": "remark","orderable": false}
                ],
                "columnDefs" : [ {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 0 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 1 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 2 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 3 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 4 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 5 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 6 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 7 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 8 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 9 ]
                } , {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 9 ]
                } ],
                "order": [[2, "asc"],[6, "asc"]],
                "drawCallback": function( settings ) {
                    $("#adjustSkuCompleteTable tbody").find("tr").each(function () {
                        for(var i=0;i<11;i++){
                            $(this).children('td:eq('+i+')').attr("title", $(this).children('td:eq('+i+')').text());
                        }
                    });
                }
            });

            // 文字过长截断显示悬浮框
            $("#adjustSkuCompleteTable").tooltip({
                selector: ".tooltip-column-detail-5",
                container: "body",
                title: function() {
                    if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                        return $(this).text();
                    }
                }
            });
        } else {
            adjustSkuCompleteTable.draw();
        }
    } else {
        $('#adjustSkuCompleteTable').hide();
        $('#adjustSkuTable').show();
        if (adjustSkuTable==null){
            adjustSkuTable = $('#adjustSkuTable').DataTable({
                "autoWidth": false,
                "processing": true,
                "serverSide": true,
                // "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "dom": '<"bottom"rtflp>',
                "searching": false,
                // "pagingType": "full_numbers",
                "paging": false,
                "deferRender": true,
                "ordering": false,
                "ajax": {
                    "url": "/extAdjust/getAdjustSku.action?adjustId="+$('#myid', window.parent.document).val()
                },
                "columns": [
                    {"data": "goodsCode","orderable": false},
                    {"data": "goodsName","orderable": false},
                    {"data": "skuCode","orderable": false},
                    {"data": "skuName","orderable": false},
                    {"data": "stockTypeName","orderable": false},
                    {"data": "batchCode","orderable": false},
                    {"data": "productDate","orderable": false},
                    {"data": "qty","orderable": false},
                    {"data": "goodsSkuCost","orderable": false,"render": numberParser},
                    {"data": "remark","orderable": false}
                ],
                "columnDefs" : [ {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 0 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 1 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 2 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 3 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 4 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 5 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 6 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 7 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 8 ]
                }, {
                    "className" : "truncate-text tooltip-column-detail",
                    "targets" : [ 9 ]
                } ],
                "order": [[2, "asc"],[6, "asc"]],
                "drawCallback": function( settings ) {
                    $("#adjustSkuTable tbody").find("tr").each(function () {
                        for(var i=0;i<10;i++){
                            $(this).children('td:eq('+i+')').attr("title", $(this).children('td:eq('+i+')').text());
                        }
                    });
                }
            });

            // 文字过长截断显示悬浮框
            $("#adjustSkuTable").tooltip({
                selector: ".tooltip-column-detail-5",
                container: "body",
                title: function() {
                    if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                        return $(this).text();
                    }
                }
            });
        } else {
            adjustSkuTable.draw();
        }
    }

}

var numberParser = function(data){
    var returnValue = "-";
    var numberData = parseFloat(data);
    if(numberData===+numberData){
        returnValue = numberData.toFixed(2);
    }
    return returnValue;
};